﻿using System;
using System.Threading.Tasks;
using OurDailyBread;
using OurDailyBread.Helpers;

namespace OurDailyBread.Model
{
    public class BreadDataService : IDataService
    {
        //string breadWebAPIUri = "http://localhost:50243/api/content";
        string breadWebAPIUri = "http://breadwebapi.azurewebsites.net/api/content";

        public async void  GetData(Action<Object, Exception> callback)
        {
            // Use this to connect to the actual data service
            try
            {
                App app = (App)OurDailyBread.App.Current;
                string BreadDate = Util.GetShortNavUrl(app.Context.currentDisplayDate);
                string url = breadWebAPIUri + "?BreadDate=" + BreadDate;
                string getResults = await HttpService.Get(new Uri(url));

                callback(getResults, null);
            }
            catch (Exception ex)
            {
                callback(null, ex);
            }
        }
            
    }
}